package br.edu.ifrn.dao;

import java.util.List;

import javax.persistence.EntityManager;

public abstract class AbstractDAO {
	protected static EntityManager em;

	public static void setEntityManager(EntityManager e) {
		em = e;
	}

	public <E> void salvar(E entity) {
		if (entity != null)
			em.merge(entity);
		else
			em.persist(entity);
	}

	public <E> void remover(E entity) {
		E e = em.merge(entity);
		em.remove(e);
	}

	public abstract <E> List<E> listar();

	public <E> E findById(Class<E> classe, Long id) {
		return em.find(classe, id);
	}

}
